package com.demo.readers;

import com.demo.common.model.Readers;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * 本 com.demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法
 * 详见 JFinal 俱乐部: http://jfinal.com/club
 * 
 * ReaderValidator.
 */
public class ReaderValidator extends Validator {
	
	protected void validate(Controller controller) {
		//validateRequiredString("readers.readerno", "readerNoMsg", "请输入读者编号!");
		validateRequiredString("readers.readername", "readerNameMsg", "请输入读者姓名!");
		validateRequiredString("readers.sex", "sexMsg", "请选择性别!");
		validateRequiredString("readers.tel", "telMsg", "请输入电话!");
	}
	
	protected void handleError(Controller controller) {
		controller.keepModel(Readers.class);
		
		String actionKey = getActionKey();
		if (actionKey.equals("/readers/save"))
			controller.render("add.html");
		else if (actionKey.equals("/readers/update"))
			controller.render("edit.html");
	}
}
